package com.ruoyi.district.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.district.Vo.CityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.district.domain.FangCity;
import com.ruoyi.district.service.IFangCityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 城市区域Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/city")
public class FangCityController extends BaseController
{
    @Autowired
    private IFangCityService fangCityService;

    /**
     * 查询城市区域列表
     */
   // @RequiresPermissions("district:city:list")
    @GetMapping("/list")
    public TableDataInfo list(FangCity fangCity)
    {
        startPage();
        List<FangCity> list = fangCityService.selectFangCityList(fangCity);
        return getDataTable(list);
    }

    @GetMapping("/listCity")
    public TableDataInfo listCity(CityVo cityVo)
    {
        startPage();
        List<FangCity> list = fangCityService.listCity(cityVo);
        return getDataTable(list);
    }


    /**
     * 导出城市区域列表
     */
    @RequiresPermissions("district:city:export")
    @Log(title = "城市区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FangCity fangCity)
    {
        List<FangCity> list = fangCityService.selectFangCityList(fangCity);
        ExcelUtil<FangCity> util = new ExcelUtil<FangCity>(FangCity.class);
        util.exportExcel(response, list, "城市区域数据");
    }

    /**
     * 获取城市区域详细信息
     */
    @RequiresPermissions("district:city:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(fangCityService.selectFangCityById(id));
    }

    /**
     * 新增城市区域
     */
    @RequiresPermissions("district:city:add")
    @Log(title = "城市区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FangCity fangCity)
    {
        return toAjax(fangCityService.insertFangCity(fangCity));
    }

    /**
     * 修改城市区域
     */
    @RequiresPermissions("district:city:edit")
    @Log(title = "城市区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FangCity fangCity)
    {
        return toAjax(fangCityService.updateFangCity(fangCity));
    }

    /**
     * 删除城市区域
     */
    @RequiresPermissions("district:city:remove")
    @Log(title = "城市区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(fangCityService.deleteFangCityByIds(ids));
    }
}
